using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAL;
using Utility;

namespace BUS
{
    public class HoaDon_BUS
    {
        public static int Insert(HoaDon_DTO hoaDon)
        {
            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();
          return  hoaDonDAL.Insert(hoaDon);
        }
        public static void Update(HoaDon_DTO hoaDon)
        {
            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();
            hoaDonDAL.Update(hoaDon);
        }
        public static void UpdateTT(HoaDon_DTO hoaDonTT)
        {

            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();

            hoaDonDAL.UpdateTONGTIEN(hoaDonTT);
        }
        public static void Delete(int iD)
        {
            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();
            hoaDonDAL.Delete(iD);
        }
        public static tbHoaDonCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();
            return hoaDonDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbHoaDonCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();
            return hoaDonDAL.Get(cri.Criter, 0, 0, tbHoaDonColumns.MaHD.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static HoaDon_DTO GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbHoaDonColumns.MaHD.ToString(), Condition.EQUAL, iD);
            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();
            tbHoaDonCollection hoaDonCollection = hoaDonDAL.Get(cri.Criter,
                0, 0, tbHoaDonColumns.MaHD.ToString(), OrderDirection.ASC.ToString(), out total);
            if (hoaDonCollection.Count > 0)
                return hoaDonCollection[0];
            return null;
        }
        public static tbHoaDonCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();
            return hoaDonDAL.Get(cri.Criter, 1, number,
                tbHoaDonColumns.MaHD.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbHoaDonCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            HoaDon_DAL hoaDonDAL = new HoaDon_DAL();
            return hoaDonDAL.Get(cri.Criter, 1, number,
                tbHoaDonColumns.MaHD.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
